package com.leo.huawei;

import java.math.BigInteger;

/**
 * Created by LEO on 2018/4/26.
 */
public class Solution2 {
    public static void main(String[] args) {
        System.out.println(solution(new int[]{1,0,2,0,0,2}));
    }

    public static int solution(int[] A){
        BigInteger sum = BigInteger.ZERO;
        for (int i = 0; i < A.length; i++) {
            sum = sum.add(new BigInteger("" + (1<<A[i]) ));
        }
        return getOneCount(sum);
    }
//    public static int solution(int[] A){
//        long sum = 0;
//        for (int i = 0; i < A.length; i++) {
//            sum += (1<<A[i]);
//        }
//        return getOneCount(sum);
//    }
    //计算一个二进制中1的个数
    private static int getOneCount(long a){
        int count=0;
        while(a != 0){
            if(a%2==1){
                count++;
            }
            a/=2;
        }
        return count;
    }
    //计算一个二进制中1的个数,大数版本
    private static int getOneCount(BigInteger a){
        char[] chars = a.toString(2).toCharArray();//转换为二进制
        int res = 0;
        for (int i = 0; i < chars.length; i++) {
            if (chars[i] == '1'){ res++; }
        }
        return res;
    }
}
